package com.superc.lib.ui;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import com.superc.lib.helper.KeyValue;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class KeyValueAdapter extends BaseAdapter implements List<KeyValue<String,Object>>  {

	private ArrayList<KeyValue<String,Object>> datas=new ArrayList<KeyValue<String,Object>>();
	
	public KeyValueAdapter(){}
	
	public KeyValueAdapter(KeyValue<String,Object>[] initData){
		for (KeyValue<String, Object> keyValue : initData) {
			datas.add(keyValue);
		}
	}
	
	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return datas.get(position).getValue();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView mTextView = new TextView(parent.getContext());  //(TextView)parent.findViewById(android.R.layout.simple_spinner_item);
		mTextView.setText(datas.get(position).getKey());
		return mTextView;
	}

	@Override
	public boolean add(KeyValue<String, Object> object) {
		return datas.add(object);
	}

	@Override
	public void add(int location, KeyValue<String, Object> object) {
		datas.add(location, object);
	}

	@Override
	public boolean addAll(Collection<? extends KeyValue<String, Object>> arg0) {
		return datas.addAll(arg0);
	}

	@Override
	public boolean addAll(int arg0,
			Collection<? extends KeyValue<String, Object>> arg1) {
		return datas.addAll(arg0,arg1);
	}

	@Override
	public void clear() {
		datas.clear();
	}

	@Override
	public boolean contains(Object object) {
		return datas.contains(object);
	}

	@Override
	public boolean containsAll(Collection<?> arg0) {
		return datas.containsAll(arg0);
	}

	@Override
	public KeyValue<String, Object> get(int location) {
		return datas.get(location);
	}

	@Override
	public int indexOf(Object object) {
		return datas.indexOf(object);
	}

	@Override
	public Iterator<KeyValue<String, Object>> iterator() {
		return datas.iterator();
	}

	@Override
	public int lastIndexOf(Object object) {
		return datas.lastIndexOf(object);
	}

	@Override
	public ListIterator<KeyValue<String, Object>> listIterator() {
		return datas.listIterator();
	}

	@Override
	public ListIterator<KeyValue<String, Object>> listIterator(int location) {
		return datas.listIterator(location);
	}

	@Override
	public KeyValue<String, Object> remove(int location) {
		return datas.remove(location);
	}

	@Override
	public boolean remove(Object object) {
		return datas.remove(object);
	}

	@Override
	public boolean removeAll(Collection<?> arg0) {
		return datas.removeAll(arg0);
	}

	@Override
	public boolean retainAll(Collection<?> arg0) {
		return datas.retainAll(arg0);
	}

	@Override
	public KeyValue<String, Object> set(int location,
			KeyValue<String, Object> object) {
		return datas.set(location, object);
	}

	@Override
	public int size() {
		return datas.size();
	}

	@Override
	public List<KeyValue<String, Object>> subList(int start, int end) {
		return datas.subList(start, end);
	}

	@Override
	public Object[] toArray() {
		return datas.toArray();
	}

	@Override
	public <T> T[] toArray(T[] array) {
		return datas.toArray(array);
	}


}
